<?php

/*
include_once('jcampbell_rss_test.php');

function addUserAnnouncement($title, $content)
{
	$a[] = '<tr><td valign="top" style="font:Arial, Helvetica, sans-serif; font-weight:normal; font-size:12px;" bgcolor="#c8bb8a">';
	$a[] = '<span style="font-size:14px; font-weight:bold; display:block;">';
	$a[] = $title;
	$a[] = '</span>';
	$a[] = $content;
	$a[] = '</td></tr>';
	return $a;
}


function addUserEvent($title, $content){
	$e[] = '<tr><td valign="top" style="font:Arial, Helvetica, sans-serif; font-weight:normal; font-size:12px;">';
	$e[] = '<span style="font-size:14px; font-weight:bold; display:block;padding-bottom:5px;">';
	$e[] = $title;
	$e[] = '</span>';
	$e[] = $content;
	$e[] = '</td></tr>';
	return $e;

}


function addUserPromotion($title, $content){
	$p[] = '<tr><td valign="top" style="font:Arial, Helvetica, sans-serif; font-weight:normal; font-size:12px;" bgcolor="#c8bb8a">';
	$p[] = '<span style="font-size:14px; font-weight:bold; display:block;">';
	$p[] = $title;
	$p[] = '</span>';
	$p[] = $content;
	$p[] = '</td></tr>';
	return $p;
}


function getUserContent($user)
{

	
	//pull data form rss feed for announcements, etc.
	//pull data from rss feed of events
	//return test message content for now ... 

	$url = 'http://calendar.activedatax.com/rollins/RSSSyndicator.aspx?type=N&number=5&category=51-0&numdays=1&expire=Y&binary=Y&rsstitle=Rollins+College+Events+For+Today+and+Tomorrow&rssid=11';

	$feed = get_rss_feed($url);
	
	foreach($feed as $item)
	{
		
		echo "<pre>";
 		print_r($item);
	 	echo "</pre>";
 		die;

		$child = $item->data->child->rss->child->channel->child->;
		$title = $child->title->data;
		$link = $child->link->data;
		$description = $child->description ->data;
		$pubDate = $child->pubDate->data;
		$category = $child->category->data;
	
	}
	
//addUserAnnouncement($title, $content);
//addUserEvent($title, $content);
//addUserPromotion($title, $content);

	$content = array(
		array('type'=> 'announcement', 'title'=> 'Library Taken Over by Zombies', 'content'=> 'Awesome Announcement'),
		array('type'=> 'promotion', 'title'=> 'A Free Beer for Every Letter Grade of A', 'content'=> 'Awesome Promotion'),
		array('type'=> 'event', 'title'=> 'Graduation - Myth or Reality', 'content'=> 'Awesome Event')
	);
	return $content;
}


function getMessage($user){
	$message[] = '<html><body bgcolor="#ddd5b3" style="font:Arial, Helvetica, sans-serif; color: #4e3227;">';
	$message[] = '<table id="main" width="800px"><tbody><tr><td colspan="3" bgcolor="#002c5f">';
	$message[] = '<table id="topRow" height="50px"><tbody><tr><td width="100%" colspan="3">';
	$message[] = '<<!--THIS WILL BE THE LINK TO THE LOGO-->img src="http://r-net.rollins.edu/images/header/rnet_home-registration-mark3.gif" style="float:left">';
	$message[] = '<h2 style="font:Arial; font-size:28px; color:#ddd5b3; padding-left:10px; padding-top:20px; display:inline">';
	$message[] = 'Good Morning, Rollins!</h2></td></tr></tbody></table></td></tr><tr><td>';
	$message[] = '<table id="centerRow"><tbody><tr><td colspan="3"><table><tbody><tr>';
	$content = getUserContent($user);
	$inSection = false;

	foreach($content as $key => $item){//assumes integer indexed array of items
		//OPEN SECTION
		if(!$inSection){
			$message[] = '<td valign="top"><table id="'.$content['type'].'" width="150px"><tbody>';
			$inSection = true;
		}

		switch($item['type']){
			case 'announcement':
				array_merge($message, addUserAnnouncement($item['title'], $item['content']));
				break;

			case 'promotion':
				array_merge($message, addUserPromotion($item['title'], $item['content']));
				break;

			case 'event':
				array_merge($message, addUserEvent($item['title'], $item['content']));
				break;

			default:
				throw new Exception("Unrecognized Content Type " . $content['type']);
		}

		//CLOSE SECTION
		if(isset($content[$key + 1])){
			$nextType = $content[$key + 1]['type'];

			if($content['type'] != $nextType){
				$message[] = '</tbody></table></td><td valign="top">';
				$inSection = false;
			}

		}else {
			//At End of Array... close off section content
			$message[] = '</tbody></table></td><td valign="top">';
		}
	}


	//Add the last of it.
	$message[] = '</tr></tbody></table></td></tr></tbody></table></td></tr><tr>';
	$message[] = '<td colspan="3" bgcolor="#002c5f" height="30px;"><table id="bottomRow"><tbody>';
	$message[] = '</tbody></table></td></tr></tbody></table></body></html>';

	return implode($message);
}


//ID
//user_login
//user_pass
//user_nicename
//user_email
//user_url
//user_registered
//display_name



function sendEmail(){
	$EMAIL_ROLLINS_USES_FOR_SENDER = 'donotreply@rollins.edu';
	$users = get_users();

	foreach($users as $user){
		$to = $user->user_email;
		$html_msg = getMessage($user);
		$subject = 'good morning you beautiful bastards';
		$headers  = 'MIME-Version: 1.0' . "\r\n";
		$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
		$headers .= 'From: '. $EMAIL_ROLLINS_USES_FOR_SENDER . "\r\n";

		if (mail($to, $subject, $message, $headers)) {
			//MAIL_THE_THING!!!
			echo $to;
			echo $subject;
			echo $html_msg;
			echo '';
			echo '';
		}
	}
}*/
?>



